package eu.pago.chat.gui;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.rmi.registry.Registry;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class SignUpFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JPanel titlePanel;
	JPanel loginPanel;
	JTextField usernameTextField;
	JPasswordField passField;
	JButton loginButton;
	JPanel messagePanel;
	private final Registry registry;

	public SignUpFrame(Registry registry) {
		this.registry = registry;
		this.setResizable(false);
		this.setSize(300, 150);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Sign Up:");
		this.setVisible(true);
		this.setLayout(new BorderLayout());
		add(createUserDatas(), BorderLayout.NORTH);
		add(createSignUpPanel(), BorderLayout.CENTER);
	}

	private JPanel createUserDatas() {
		JPanel newUserDataPanel = new JPanel();
		newUserDataPanel.setLayout(new GridLayout(3, 2, 1, 5));
		JLabel usernameLabel = new JLabel("Username:");
		newUserDataPanel.add(usernameLabel);
		usernameTextField = new JTextField();
		usernameTextField.setBackground(UtilColors.FADE_YELLOW);
		newUserDataPanel.add(usernameTextField);

		JLabel passwordLabel = new JLabel("Password:");
		newUserDataPanel.add(passwordLabel);
		JPasswordField passwordField = new JPasswordField();
		passwordField.setBackground(UtilColors.FADE_YELLOW);
		newUserDataPanel.add(passwordField);

		JLabel retypePassLabel = new JLabel("Password(repeat):");
		newUserDataPanel.add(retypePassLabel);
		JPasswordField retypePassField = new JPasswordField();
		retypePassField.setBackground(UtilColors.FADE_YELLOW);
		newUserDataPanel.add(retypePassField);

		newUserDataPanel.setBackground(UtilColors.BLUE_NUANCE);
		return newUserDataPanel;
	}

	private JPanel createSignUpPanel() {
		JPanel signUpPanel = new JPanel();
		JButton signUpButton = new JButton("Sign Up");
		ActionListener listener = new SignUpListener(this, registry);
		signUpButton.addActionListener(listener);
		signUpPanel.add(signUpButton);
		signUpPanel.setBackground(UtilColors.BLUE_NUANCE);
		return signUpPanel;
	}
}
